// components/prtSc/prtSc.js
let app = getApp()
let timeUtil = require("../../utils/timeUtils")
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    question: ""
  },

  /**
   * 组件的初始数据
   */
  data: {},

  /**
   * 组件的方法列表
   */
  methods: {
    feedback: async function (params) {
      //这里要拿到题号和当前练习章节
      let selectLib = app.globalData.selectLib
      let question = this.data.question
      console.log(question)
      let res1 = await wx.cloud.database().collection("feedBack").where({
        selectLib: selectLib,
        question: question,
        updated:false
      }).get()
      if (res1.data.length > 0) { //如果有人已经反馈过了，就不用反馈了
        wx.showToast({
          title: '有人反馈过了',
        })
      } else {
        let account = await wx.getStorageSync('user').account
        let response = await wx.cloud.database().collection("feedBack").add({
          data: {
            account: account,
            selectLib: selectLib,
            question: question,
            time: Date.now(),
            updated:false
          }
        }).then()
        if (response.errMsg == "collection.add:ok") {
          wx.showToast({
            icon: "success",
            title: '感谢您的反馈',
          })
        }
      }
    }
  }
})